package usersOnlineService

import (
	"chart.zozoo.net/app/dao/usersOnlineDao"
	"chart.zozoo.net/core/conf"
	"time"
)

// Update 修改用户在线状态
func Update(uid string, status int, addr string) (err error) {
	updateField := make(map[string]interface{})
	updateField["status"] = status
	updateField["addr"] = addr
	if status == 1 {
		//登录
		updateField["login_at"] = time.Now()
		updateField["host"] = conf.Conf.Server.Host
	} else {
		//退出
		updateField["logout_at"] = time.Now()
	}

	err = usersOnlineDao.UpdateByUid(uid, updateField)
	if err != nil {
		return err
	}

	//更新用户在线缓存
	_, err = Info(uid, "delete")
	return err
}
